package com.jichaoyun.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jichaoyun.dao.mapper.PipelossAlarmMapper;
import com.jichaoyun.model.entity.PipeLossAlarm;
import com.jichaoyun.service.PipelossAlarmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Service
public class PipelossAlarmServiceImpl  extends ServiceImpl<PipelossAlarmMapper, PipeLossAlarm>
 implements PipelossAlarmService {

    @Autowired
    private PipelossAlarmMapper pipelossAlarmMapper;
    @Override
    public IPage<PipeLossAlarm> getPipelossAlarm(String lineId, String start, String end, Integer pageNo, Integer pageSize) {
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime startTime = LocalDateTime.parse(start,dateTimeFormatter);
        LocalDateTime endTime = LocalDateTime.parse(end,dateTimeFormatter);

        IPage<PipeLossAlarm> objectPage = new Page<>(pageNo, pageSize);
        LambdaQueryWrapper<PipeLossAlarm> wp = new LambdaQueryWrapper<>();
        wp.eq(lineId!=null,PipeLossAlarm::getLineId,lineId)
                        .between(PipeLossAlarm::getStartTime,startTime,endTime)
                .orderByAsc(PipeLossAlarm::getStartTime);
        IPage<PipeLossAlarm> pipeLossAlarmPage = pipelossAlarmMapper.selectPage(objectPage, wp);

        return pipeLossAlarmPage;
    }
}
